from sitepal.sitebase.tests.models.base import BaseTest
from sitepal.sitebase.models            import Tree

class TreeTest(BaseTest):
    def create_object(self,obj,save=True,**kwargs):
        self.assertTrue(isinstance(obj,Tree))
        obj.parent = kwargs.get('parent')
        return self.save_object(obj,save=save)

    def verify_object(self,obj,**kwargs):
        self.assertTrue(obj.parent == kwargs.get('parent'))
        if obj.parent:
            self.assertTrue (obj.ancestors == [obj.parent] + obj.parent.ancestors)
            self.assertTrue (obj.level > 0)
            self.assertTrue (obj.level == obj.parent.level + 1)
            self.assertTrue (obj in obj.parent.children)
            self.assertTrue (obj in obj.parent.descendants)
            self.assertFalse(obj in obj.siblings)
        else:
            self.assertTrue(obj.ancestors == [])
            self.assertTrue(obj.level == 0)

        

